import logging
import os

import allure
import pymysql
import requests



@allure.step("2.发起HTTP请求")
def     launch_request(**data):
    res = requests.request(**data)
    # print(res.json())
    logging.info(f"2.发起HTTP请求，响应文本为：{res.text}")
    allure.attach(f"2.发起HTTP请求，响应文本为：{res.text}",name="HTTP响应文本")


    return res

def launch_jdbc_Request(sql,index = 0):
    conn = pymysql.Connect(
        # host=DB_HOST,
        # port=DB_PORT,
        # database=DB_NAME,
        # user=DB_USER,
        # password=DB_PASSWORD,
        # charset=DB_CHARSET
        **eval(os.environ["DB"]),
        charset="utf8"
    )
    cur = conn.cursor()
    cur.execute(sql)
    res_sql = cur.fetchall()
    cur.close()
    conn.close()
    return res_sql[index][index]


